//
//  PayQueryCell.m
//  PropertyMananger
//
//  Created by Mansion on 17/2/25.
//  Copyright © 2017年 BH. All rights reserved.
//

#import "PayQueryCell.h"

@implementation PayQueryCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
+ (instancetype)cellWithTableView:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath
{
    static NSString * cellID = @"PayQueryCellID";
    PayQueryCell * cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (!cell) {
        
        cell = [[PayQueryCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        //title
        self.monthLabel = [[UILabel alloc]init];
        [self.contentView addSubview:self.monthLabel];
        self.monthLabel.font = BHFont(15);
        self.monthLabel.textAlignment = NSTextAlignmentLeft;
        self.monthLabel.textColor = Theme_Color;
        self.monthLabel.text = @"缴费月份:2017-03";
        
        [self.monthLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.leading.equalTo(self.contentView).with.offset(15);
            make.top.equalTo(self.contentView).with.offset(15);
            make.size.mas_equalTo(CGSizeMake(BHscreenW - 30, 30));
        }];
        
        UIView * lineView = [[UIView alloc]init];
        [self.contentView addSubview:lineView];
        lineView.backgroundColor = BHGrayColor;
        
        [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
            
            make.left.equalTo(self.contentView).with.offset(15);
            make.bottom.equalTo(self.monthLabel.mas_bottom).with.offset(15);
            make.size.mas_equalTo(CGSizeMake(BHscreenW - 15, 1));
        }];
        
        self.arrowImg = [[UIImageView alloc]init];
        [self.contentView addSubview:self.arrowImg];
        self.arrowImg.image = [UIImage imageNamed:@"ico_work_order_next"];
        
        [self.arrowImg mas_makeConstraints:^(MASConstraintMaker *make) {
            make.trailing.equalTo(self.contentView).with.offset(-15);
            make.centerY.equalTo(self.monthLabel).with.offset(0);
            make.size.mas_equalTo(CGSizeMake(8, 14));
        }];
        
        self.floorLabel = [[UILabel alloc]init];
        [self.contentView addSubview:self.floorLabel];
        self.floorLabel.font = BHFont(15);
        self.floorLabel.textAlignment = NSTextAlignmentLeft;
        self.floorLabel.textColor = BHColor(102, 102, 102);
        self.floorLabel.text = @"楼  号:  6栋一单元";
        
        [self.floorLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.leading.equalTo(self.contentView).with.offset(15);
            make.top.equalTo(lineView).with.offset(15);
            make.size.mas_equalTo(CGSizeMake(BHscreenW - 30, 30));
        }];
        
        
        self.roomNumLabel = [[UILabel alloc]init];
        [self.contentView addSubview:self.roomNumLabel];
        self.roomNumLabel.font = BHFont(15);
        self.roomNumLabel.textAlignment = NSTextAlignmentLeft;
        self.roomNumLabel.textColor = BHColor(102, 102, 102);
        self.roomNumLabel.text = @"房间号:  608";
        
        [self.roomNumLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.leading.equalTo(self.contentView).with.offset(15);
            make.top.equalTo(self.floorLabel.mas_bottom).with.offset(5);
            make.size.mas_equalTo(CGSizeMake(BHscreenW - 30, 30));
        }];

        self.iconImg = [[UIImageView alloc]init];
        [self.contentView addSubview:self.iconImg];
        self.iconImg.image = [UIImage imageNamed:@"ico_seal_unpaid"];
        
        [self.iconImg mas_makeConstraints:^(MASConstraintMaker *make) {
            make.trailing.equalTo(self.contentView).with.offset(-15);
            make.top.equalTo(lineView.mas_bottom).with.offset(10);
            make.size.mas_equalTo(CGSizeMake(80, 80));
        }];

    }
    
    return self;
}
- (void)setModel:(QueryResultModel *)model{

    _model = model;
    DLog(@"选择的类型 ===%ld",self.selectedType);
    if (self.selectedType == 0) {
        
        NSString * monthStr = [NSString stringWithFormat:@"缴费日期:%@",model.GenerateDate];
        self.monthLabel.text = monthStr;
        
        NSString * floorStr = [NSString stringWithFormat:@"楼号:%@%@",model.BuildName,model.UnitName];
        self.floorLabel.text = floorStr;
        NSString * roomNumStr = [NSString stringWithFormat:@"房间号:%@",model.RoomName];
        self.roomNumLabel.text = roomNumStr;
        
        DLog(@"点击了物业缴费");
        //楼号
        NSRange  rang = [floorStr rangeOfString:@":"];
        NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:floorStr];
        [string addAttribute:NSForegroundColorAttributeName value:BHColor(51, 51, 51) range:NSMakeRange(rang.location,floorStr.length-rang.location)];
         self.floorLabel.attributedText = string;
        
        //房间号
        NSRange  rang1 = [roomNumStr rangeOfString:@":"];
        NSMutableAttributedString *string1 = [[NSMutableAttributedString alloc] initWithString:roomNumStr];
        [string1 addAttribute:NSForegroundColorAttributeName value:BHColor(51, 51, 51) range:NSMakeRange(rang1.location,roomNumStr.length-rang1.location)];
        self.roomNumLabel.attributedText = string1;
        
        if ([model.ChargeState isEqualToString:@"未缴费"]) {
            
            self.iconImg.image = [UIImage imageNamed:@"ico_seal_unpaid"];
            
        }else if ([model.ChargeState isEqualToString:@"已缴费"]){
            
            self.iconImg.image = [UIImage imageNamed:@"ico_seal_already_paid"];
            
        }
        
        
    }else if (self.selectedType == 1){
    
        NSString * parkingPayStr = [NSString stringWithFormat:@"缴费截止时间:%@",model.EndTime];
        self.monthLabel.text = parkingPayStr;
        
        NSString * carNoStr = [NSString stringWithFormat:@"车牌号:%@",model.CarNo];
        self.floorLabel.text = carNoStr;
        
        NSString * nameStr = [NSString stringWithFormat:@"车主姓名:%@",model.Expr1];
        self.roomNumLabel.text = nameStr;
        
        self.iconImg.image = [UIImage imageNamed:@"ico_seal_already_paid"];
        
    
    }
     DLog(@"缴费状态 === %@",model.ChargeState);


}
@end
